package com.xiaoxin.project.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xiaoxin.framework.aspectj.lang.enums.DataSourceType;
import com.xiaoxin.framework.datasource.DynamicDataSourceContextHolder;
import com.xiaoxin.project.system.domain.SysOrder;
import com.xiaoxin.project.system.mapper.SysOrderMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

/**
 * 广播表测试
 *
 * @author ZhangXX
 * @version 1.0
 * @data 2021/5/18 22:49
 */
@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles("test1")
public class test1 {
    @Autowired
    private SysOrderMapper sysOrderMapper;

    /**
     * in
     */
    @Test
    public void test() {
        DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.SHARDING.name());
        LambdaQueryWrapper<SysOrder> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(SysOrder::getOrderId, 742512139708661761L, 837261421916979200L);
        List<SysOrder> sysOrders = sysOrderMapper.selectList(queryWrapper);
        System.out.println(sysOrders);
        DynamicDataSourceContextHolder.clearDataSourceType();
    }

    /**
     * BETWEEN AND
     */
    @Test
    public void test2() {
        DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.SHARDING.name());
        LambdaQueryWrapper<SysOrder> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.between(SysOrder::getOrderId, 742512139708661761L, 837261421916979200L);
        List<SysOrder> sysOrders = sysOrderMapper.selectList(queryWrapper);
        System.out.println(sysOrders);
        DynamicDataSourceContextHolder.clearDataSourceType();
    }


}